package com.application.screen;
/** ============================================================================= **/
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.example.sispakmobile.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ExpandableListView;
import android.widget.Toast;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.ExpandableListView.OnGroupClickListener;
import android.widget.ExpandableListView.OnGroupCollapseListener;
import android.widget.ExpandableListView.OnGroupExpandListener;
/** ============================================================================= **/
public class HomeScreen extends Activity{
	HomeListAdapter listAdapter;
	ExpandableListView expListView;
	List<String> listDataHeader;
	HashMap<String, List<String>> listDataChild;
	/* =========================================================================== */
	public void onCreate(Bundle  savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.home_screen);

		// get the listview
		expListView						= (ExpandableListView) findViewById(R.id.lvExp);

		// preparing list data
		prepareListData();

		listAdapter 					= new HomeListAdapter(this, listDataHeader, listDataChild);

		// setting list adapter
		expListView.setAdapter(listAdapter);

		Button btnKembali				= (Button) findViewById(R.id.btnKembali);

		/* ======================================================================= */
		/** 
		 * Start Listener */
		expListView.setOnGroupClickListener(new OnGroupClickListener() {
			@Override
			public boolean onGroupClick(ExpandableListView parent, View v,
					int groupPosition, long id) {
				return false;
			}
		});
		/* ======================================================================= */
		expListView.setOnGroupExpandListener(new OnGroupExpandListener() {

			@Override
			public void onGroupExpand(int groupPosition) {
				Toast.makeText(getApplicationContext(),
						listDataHeader.get(groupPosition) + " Expanded",
						Toast.LENGTH_SHORT).show();
			}
		});
		/* ======================================================================= */
		expListView.setOnGroupCollapseListener(new OnGroupCollapseListener() {

			@Override
			public void onGroupCollapse(int groupPosition) {
				Toast.makeText(getApplicationContext(),
						listDataHeader.get(groupPosition) + " Collapsed",
						Toast.LENGTH_SHORT).show();

			}
		});
		/* ======================================================================= */
		expListView.setOnChildClickListener(new OnChildClickListener() {

			@Override
			public boolean onChildClick(ExpandableListView parent, View v,
					int groupPosition, int childPosition, long id) {
				// TODO Auto-generated method stub
				Toast.makeText(
						getApplicationContext(),
						listDataHeader.get(groupPosition)
								+ " : "
								+ listDataChild.get(
										listDataHeader.get(groupPosition)).get(
										childPosition), Toast.LENGTH_SHORT)
						.show();
				return false;
			}
		});
		/* ======================================================================= */		
		btnKembali.setOnClickListener(new OnClickListener() {	
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent welcomeScreen	= new Intent(HomeScreen.this, WelcomeScreen.class);

				/** 
				 * Send Parameter */
				Bundle bundle 			= new Bundle();
				bundle.putString("nama", "Randhika");
				
				welcomeScreen.putExtras(bundle);
	            startActivityForResult(welcomeScreen, 0);
			}
		});
		/* ======================================================================= */
	}
	/* =========================================================================== */
	private void prepareListData(){
		listDataHeader 					= new ArrayList<String>();
		listDataChild = new HashMap<String, List<String>>();

		// Adding child data
		listDataHeader.add("Master Identifikasi");
		listDataHeader.add("Master Kesimpulan");
		listDataHeader.add("Master Kamus");
		listDataHeader.add("Master Target");
		listDataHeader.add("Master Arahan");

		// Master Identifikasi
		List<String> identifikasi = new ArrayList<String>();
		identifikasi.add("Tambah Identifikasi");
		identifikasi.add("Ubah Identifikasi");
		identifikasi.add("Hapus Identifikasi");

		// Master Identifikasi
		List<String> kesimpulan = new ArrayList<String>();
		kesimpulan.add("Tambah Kesimpulan");
		kesimpulan.add("Ubah Kesimpulan");
		kesimpulan.add("Hapus Kesimpulan");

		// Master Identifikasi
		List<String> kamus = new ArrayList<String>();
		kamus.add("Tambah Kamus");
		kamus.add("Ubah Kamus");
		kamus.add("Hapus Kamus");

		// Master Identifikasi
		List<String> target = new ArrayList<String>();
		target.add("Tambah Target");
		target.add("Ubah Target");
		target.add("Hapus Target");

		// Master Identifikasi
		List<String> arahan = new ArrayList<String>();
		arahan.add("Tambah Arahan");
		arahan.add("Ubah Arahan");
		arahan.add("Hapus Arahan");

		listDataChild.put(listDataHeader.get(0), identifikasi); // Header, Child data
		listDataChild.put(listDataHeader.get(1), kesimpulan); // Header, Child data
		listDataChild.put(listDataHeader.get(2), kamus); // Header, Child data
		listDataChild.put(listDataHeader.get(3), target); // Header, Child data
		listDataChild.put(listDataHeader.get(4), arahan); // Header, Child data
	}
	/* =========================================================================== */
}
/** ============================================================================= **/